package com.Framework.interceptor;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

@Aspect
@Component
public class RequestParamValid {
	/**
	 * @param thisJoinPoint
	 * @param partner
	 * @param accesstoken
	 * @return
	 * @throws Throwable 
	 */
	
	@Around("execution(* com.vcredit.creditcat.web..*(..))")  
	public Object InvokeMethod(ProceedingJoinPoint thisJoinPoint) throws Throwable{
		Object[] args = thisJoinPoint.getArgs();
		for(Object o : args){
			if(o instanceof BindingResult){
				BindingResult bindingResult = (BindingResult)o; 
				//异常处理
				if(bindingResult.hasErrors()){
					StringBuffer errorsb = new StringBuffer();
					for(ObjectError error:bindingResult.getAllErrors()){
						errorsb.append(error.toString());
					}
					throw new Exception(errorsb.toString());
				}
				
				
			}
		}
		return thisJoinPoint.proceed();
	}
	

}